/*
 * @lc app=leetcode.cn id=2231 lang=typescript
 *
 * [2231] 按奇偶性交换后的最大数字
 */

// @lc code=start
function largestInteger(num: number): number {
    const arr = num
        .toString()
        .split("")
        .map((i) => parseInt(i));
    for (let i = 0; i < arr.length; i++) {
        const isOdd = arr[i] % 2;
        for (let j = i + 1; j < arr.length; j++) {
            if (isOdd === arr[j] % 2) {
                if (arr[j] > arr[i]) [arr[j], arr[i]] = [arr[i], arr[j]];
            }
        }
    }
    return parseInt(arr.join(""));
}
// @lc code=end
